package cn.itrip.utlis;

import cn.itrip.pojo.ItripUser;
import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;

import javax.annotation.Resource;

/**
 * Token验证
 * Created by hanlu on 2017/5/7.
 */
public class ValidationToken {

    private Logger logger = Logger.getLogger(ValidationToken.class);
    @Resource
    private RedisUtils redisUtils;

    public RedisUtils getRedisUtils() {
        return redisUtils;
    }

    public void setRedisUtils(RedisUtils redisUtils) {
        this.redisUtils = redisUtils;
    }

    public ItripUser getCurrentUser(String tokenString){

        ItripUser itripUser = null;
        if(null == tokenString || "".equals(tokenString)){
            return null;
        }
        try{
            String userInfoJson =redisUtils.getValue(tokenString);
            itripUser = JSONObject.parseObject(userInfoJson,ItripUser.class);
        }catch(Exception e){
            itripUser = null;
        }
        return itripUser;
    }

}
